package mmc.server.shell.ops.utility;

import java.util.Collection;

import mmc.cell.ServerCell;
import mmc.server.Server;
import mmc.server.shell.Shell;
import mmc.server.shell.ShellException;
import mmc.server.shell.ops.Function;

public class Status extends Function {

    public Status(String text) throws ShellException {
        super(text, "status", 0, true);
    }

	@Override
    public double execute() {
		Runtime r = Runtime.getRuntime();
		Shell.out.printf("Memory: %6.2f %% (%.2f GB used of %.2f GB total mem) \n",100*(r.totalMemory()-r.freeMemory())/(float)(r.totalMemory()),(r.totalMemory()-r.freeMemory())/1024.0f/1024.0f/1024.0f,r.totalMemory()/1024.0f/1024.0f/1024.0f);

		int compressedCells = 0;
		Collection<ServerCell> cells = Server.instance.getScene().getCellManager().debug_getAllCells();
		for(ServerCell c : cells){
			if(c.isCompressed()) compressedCells++;
		}
		
		Shell.out.printf("Cells: %d cells loaded, %d cells compressed (%.2f %%)\n", cells.size(), compressedCells, compressedCells*100.0f/cells.size());
		
    	return 0;
    }
    
    public static String getDescription(){
    	return formatHelpString("status()","prints server status");
    }

}
